class PythonIsTrash:
    def __init__(self, a):
        self.a = int(a)
        self.astr = a
        self.counter = 0

    def check_whole(self):
        for i in range(1, self.a):
            if self.a % i == 0:
                self.counter += 1
        if self.counter < 2:
            print(self.a)
            return True
        else:
            return False

    def check_trip(self):
        b = ""
        b += self.astr[0] + self.astr[1] + self.astr[2]
        self.counter = 0
        for i in range(1, int(b)):
            if int(b) % i == 0:
                self.counter += 1
        if self.counter < 2:
            print(int(b))
            return True
        else:
            b = ""
            b += self.astr[1] + self.astr[2] + self.astr[3]
            self.counter = 0
            for i in range(1, int(b)):
                if int(b) % i == 0:
                    self.counter += 1
            if self.counter < 2:
                print(int(b))
                return True
            else:
                return False

    def check_dos(self):
        b = ""
        b += self.astr[0] + self.astr[1]
        self.counter = 0
        for i in range(1, int(b)):
            if int(b) % i == 0:
                self.counter += 1
        if self.counter < 2:
            print(int(b))
            return True
        else:
            b = ""
            b += self.astr[1] + self.astr[2]
            self.counter = 0
            for i in range(1, int(b)):
                if int(b) % i == 0:
                    self.counter += 1
            if self.counter < 2:
                print(int(b))
                return True
            else:
                b = ""
                b += self.astr[2] + self.astr[3]
                self.counter = 0
                for i in range(1, int(b)):
                    if int(b) % i == 0:
                        self.counter += 1
                if self.counter < 2:
                    print(int(b))
                    return True
                else:
                    return False


n = input()
c = PythonIsTrash(n)
if c.check_whole():
    pass
elif c.check_trip():
    pass
elif c.check_dos():
    pass
else:
    print(0)
